//
//  MTVerCodeApiManager.m
//  MeToo
//
//  Created by 俊松何 on 2018/7/5.
//  Copyright © 2018年 tianxie. All rights reserved.
//

#import "MTVerCodeApiManager.h"

static MTVerCodeApiManager *vermanger = nil;
@implementation MTVerCodeApiManager

+(MTVerCodeApiManager *)manager
{
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        vermanger = [[MTVerCodeApiManager alloc] init];
    });
    return vermanger;
    
}


/**
 获取验证码
 
 @param countryCode 地区编码
 @param phone 手机号
 @param completionBlock 完成block
 */
-(void)getVerCode:(NSString *)countryCode
            phone:(NSString *)phone
       completion:(void (^)(MTError *mterror))completionBlock
{
    NSDictionary *param = @{@"countryCode":countryCode,@"phone":phone};
    [[MTHttpTool shareTool] postPath:@"/commons/verify_code/get" parameters:param success:^(MTBaseData *datamodel) {
        completionBlock(nil);
    } failer:^(MTError *error) {
        completionBlock(error);
    }];
}

/**
 获取地区编码列表
 
 @param completionBlock 完成block
 */
-(void)getCountryCodesWithCompletion:(void (^)(NSMutableArray<MMCountry *> *codes, MTError *mterror))completionBlock
{
    [[MTHttpTool shareTool] getPath:@"/commons/verify_code/get_country_codes" parameters:nil success:^(MTBaseData *datamodel) {
        NSMutableArray *tempArray = [MMCountry mj_objectArrayWithKeyValuesArray:datamodel.data];
        completionBlock(tempArray,nil);
    } failer:^(MTError *error) {
        completionBlock(nil,error);
    }];
}

/**
 获取默认地区编码
 
 @param completionBlock 完成block
 */
-(void)getDefaultCountryCodeWithCompletion:(void (^)(MMCountry *codes, MTError *mterror))completionBlock
{
    
    [[MTHttpTool shareTool] getPath:@"/commons/verify_code/get_default_country_code" parameters:nil success:^(MTBaseData *datamodel) {
        MMCountry *model = [MMCountry mj_objectWithKeyValues:datamodel.data];
        completionBlock(model,nil);
    } failer:^(MTError *error) {
        completionBlock(nil,error);
    }];
    
    
}



/**
 验证验证码是否正确
 
 @param phone 手机号
 @param countryCode 地区编码
 @param code 验证码
 @param completionBlock 完成block
 */
-(void)verifyCodeWithPhone:(NSString *)phone
               countryCode:(NSString *)countryCode
                      code:(NSString *)code
                completion:(void (^)(MTError *mterror))completionBlock
{
    NSDictionary *param = @{@"countryCode":countryCode,@"phone":phone,@"code":code};
    [[MTHttpTool shareTool] postPath:@"/commons/verify_code/verify" parameters:param success:^(MTBaseData *datamodel) {
        completionBlock(nil);
    } failer:^(MTError *error) {
        completionBlock(error);
    }];
}

@end
